package org.amse.korovkin.ciphering.view;

import java.io.IOException;
import javax.swing.*;
import java.awt.*;

public class CipheringJFrame extends JFrame{
    public static final String LAST_FILE_PATH = "lastFilePath.txt";
    private String keyPath;
    private String statisticPath;
    private TextJPanel srcJPanel = new TextJPanel("Source Text");
    private TextJPanel dstJPanel = new TextJPanel("Destination Text");
    private MyJMenuBar menuBar = new MyJMenuBar(this);
    private MyJToolBar toolBar = new MyJToolBar(this);
    private final int height = 600;
    private final int width = 800;

    public CipheringJFrame() {
        super("Ciphering");
        setSize(width, height);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLocation(200, 100);
        setMaximizedBounds(new Rectangle(1024,768));// why isn't working?
        setMinimumSize(new Dimension(width / 2, height / 2));

        JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, srcJPanel, dstJPanel );
        sp.setOneTouchExpandable(true);
        sp.setDividerLocation(400-10);
        sp.setDividerSize(10);
        sp.setResizeWeight(0.5);
        sp.setAlignmentX(CENTER_ALIGNMENT);

        this.setJMenuBar(menuBar);
        this.add(toolBar);
        Container c = getContentPane();
        c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS));
        c.add(sp);

        setVisible(true);
    }
    public String getSrcFilePath() {
        return srcJPanel.getFilePath();
    }
    public void setSrcFilePath(String filePath) {
        srcJPanel.setFilePath(filePath);
    }
    public void setDstText(String filePath) throws IOException {
        dstJPanel.loadText(filePath);
        dstJPanel.setFilePath(filePath);
    }
     public void setSrcText(String filePath) throws IOException {
        srcJPanel.loadText(filePath);
        srcJPanel.setFilePath(filePath);
    }
    public void clearSrc() {
        srcJPanel.setText("");
        srcJPanel.setFilePath(null);
    }
    public void clearDst() {
        dstJPanel.setText("");
        dstJPanel.setFilePath(null);
    }
    public String getKeyPath() {
        return keyPath;
    }
    public void setKeyPath(String path) {
        keyPath = path;
    }
    public String getStatisticPath() {
        return statisticPath;
    }
    public void setStatisticPath(String path) {
        statisticPath = path;
    }
    public void exchange() {
        String buf = srcJPanel.getText();
        srcJPanel.setText(dstJPanel.getText());
        dstJPanel.setText(buf);
        buf = srcJPanel.getFilePath();
        srcJPanel.setFilePath(dstJPanel.getFilePath());
        dstJPanel.setFilePath(buf);
    }

}

